




//类 对象

//java

//class Car{
//  Car(){

//   }
//}

// function Car(n,p,a){
//     this.carName=n;
//     this.carPrice=p;
//     this.carAddress=a;
//     this.getCarPrice=function(){
//         return this.carPrice;
//     }
// }

// let car1=new Car("xiaomi",20,"北京市")
// console.log(car1.getCarPrice())


function StudentInForm(sname,sgender,sscores){
    this.name=sname;
    this.gender=sgender;
    this.scores=sscores;
    this.getScoreSum=function(){
        let sum=0;
        if(Array.isArray(sscores)){
            for (let index = 0; index < this.scores.length; index++) {
                sum=sum+this.scores[index];
            }
            return sum;
        }
        else{
            console.log("this type is wrong")
        }

    }
}
let StudentInstance=new StudentInForm("zhangsan","man",[60,50,50]);
console.log(StudentInstance.getScoreSum());



//sql
//用户表
//username password age gender id xuehao address major

function user1 (uname,upassword,uage,ugender,uid,umajor,sscores){
    this.username = uname;
    this.password = upassword;
    this.age = uage;
    this.gender = ugender;
    this.id = uid;
    this.major = umajor;
    this.scores = sscores
  }
  function user2 (uname,upassword,uage,ugender,uid,umajor,sscores){
      this.username = uname;
      this.password = upassword;
      this.age = uage;
      this.gender = ugender;
      this.id = uid;
      this.major = umajor;
      this.scores = sscores
    }
  
  let users = [
      new user1("zhangsan","123",20,"man","2025001","计算机科学与技术",[50,60,80]),
      new user1("wangwu","345",20,"man","2025002","计算机科学与技术",[50,80,80]),
      new user1("lisi","567",20,"man","2025003","计算机科学与技术",[50,90,80]),
      new user2("tianer","888",20,"man","2025004","计算机科学与技术",[50,66,80]),
      new user2("zhaoliu","999",20,"man","2025005","计算机科学与技术",[50,60,80])
  ]
  
  for (let index = 0; index < users.length; index++) {
      if (users[index] instanceof user1) {
          let sum = 0;
          for (let index = 0; index < users[index].scores.length; index++) {
              sum = sum  + users[index].scores[index]
          }
          console.log("user1:" + users[index].username + " sum:" + sum);
      }
      else if(users[index] instanceof user2) {
          let sum = 0;
          for (let index = 0; index < users[index].scores.length; index++) {
              sum = sum  + users[index].scores[index]
          }
          console.log("user2:" + users[index].username + " sum:" + sum);
      }
  }
